//单例模式,静态方法中new实例
import { Bullets } from "./bullets";
import { GameEngine } from "./gameEngine";
export class MyPlane {
  el: HTMLDivElement;
  static instanceObj: MyPlane;
  static instance() {
    if (MyPlane.instanceObj == null) {
      MyPlane.instanceObj = new MyPlane();
    }
    return MyPlane.instanceObj;
  }
  constructor() {
    //创建战机
    this.el = document.createElement("div");
    this.el.className = "myplane";

    //把战机添加到游戏引擎的界面上
    GameEngine.instance().el.appendChild(this.el);

    //设置出生位置
    let left =
      GameEngine.instance().el.offsetWidth / 2 - this.el.offsetWidth / 2;
    this.el.style.left = left + "px"; //行内样式要带px单位

    let top = GameEngine.instance().el.offsetHeight - this.el.offsetHeight;
    this.el.style.top = top + "px"; //行内样式要带px单位
  }
  fire(){
        setInterval(()=>{
             new Bullets();
        },GameEngine.instance().level)
  }
}
